﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Twi.DataAccess.DBUtility
{
    public class DBKeyword
    {
        /// <summary>
        /// 关键字表（表名和表的列信息）
        /// </summary>
        public static DataTable DtKeyword { get; set; }

        static DBKeyword()
        {
            if (DBHelper.CurrentDBType == EnumDBType.Oracle)
            {
                DtKeyword = OracleHelper.ExecuteDataTable("SELECT * FROM sys_keyword");
            }
        }

        /// <summary>
        /// 获得序列
        /// </summary>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public static XElement GetSequenceName(string tableName)
        {
            XElement xeSequence = null;
            DataRow dr = DBKeyword.DtKeyword.Select(string.Format("UPPTBL='{0}' AND SEQ<>''", tableName.ToUpper())).FirstOrDefault();
            if (dr != null)
            {
                xeSequence = new XElement(dr["TBLCOL"].ToString(), dr["SEQ"]);
            }
            return xeSequence;
        }
    }
}
